#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

#include <sys/mman.h>
#include <string.h>
#define PAGE_SIZE 4096
       
       

int main()
{
	int fd,status=0;
	char *addr;
	char read_buf[1024];
	char fgets_buf[1024];
	fd = open("/dev/drv_key0", O_RDWR);
	if(fd < 0)
	{
		printf("app：drv_key0 open err\r\n");
		exit(1);
	}
	addr = mmap(NULL, PAGE_SIZE,PROT_READ|PROT_WRITE, MAP_SHARED,fd, 0);
	if(addr == NULL)
	{
		printf("app：mmap err\r\n");
		exit(1);
	}
	while(1)
	{
		fgets(fgets_buf, sizeof(fgets_buf), stdin);
		memcpy(addr,fgets_buf, sizeof(fgets_buf));
		sleep(1);
		read(fd, read_buf, sizeof(read_buf));
		printf("app:read_buf=%s\r\n ",read_buf);
		if(status)
		{
			status=0;
		}
		else
		{
			status=1;
		}
	}
	close(fd);
}
